Branch data Line data Source code
1 : : /**@file 2 : : * This file is part of the I/O library; it contains the standard system clock 3 : : * implementation. 4 : : * 5 : : * @see lely/io2/sys/clock.h 6 : : * 7 : : * @copyright 2018-2019 Lely Industries N.V. 8 : : * 9 : : * @author J. S. Seldenthuis <jseldenthuis@lely.com> 10 : : * 11 : : * Licensed under the Apache License, Version 2.0 (the "License"); 12 : : * you may not use this file except in compliance with the License. 13 : : * You may obtain a copy of the License at 14 : : * 15 : : * http://www.apache.org/licenses/LICENSE-2.0 16 : : * 17 : : * Unless required by applicable law or agreed to in writing, software 18 : : * distributed under the License is distributed on an "AS IS" BASIS, 19 : : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 20 : : * See the License for the specific language governing permissions and 21 : : * limitations under the License. 22 : : */ 23 : : 24 : : #include "../io2.h" 25 : : #include <lely/io2/sys/clock.h> 26 : : 27 : : #ifdef CLOCK_REALTIME 28 : : 29 : : static int io_clock_realtime_getres( 30 : : const io_clock_t *clock, struct timespec *res); 31 : : static int io_clock_realtime_gettime( 32 : : const io_clock_t *clock, struct timespec *tp); 33 : : static int io_clock_realtime_settime( 34 : : io_clock_t *clock, const struct timespec *tp); 35 : : 36 : : // clang-format off 37 : : static const struct io_clock_vtbl io_clock_realtime_vtbl = { 38 : : &io_clock_realtime_getres, 39 : : &io_clock_realtime_gettime, 40 : : &io_clock_realtime_settime 41 : : }; 42 : : // clang-format on 43 : : 44 : : const struct io_clock_realtime io_clock_realtime = { &io_clock_realtime_vtbl }; 45 : : 46 : : #endif // CLOCK_REALTIME 47 : : 48 : : #ifdef CLOCK_MONOTONIC 49 : : 50 : : static int io_clock_monotonic_getres( 51 : : const io_clock_t *clock, struct timespec *res); 52 : : static int io_clock_monotonic_gettime( 53 : : const io_clock_t *clock, struct timespec *tp); 54 : : static int io_clock_monotonic_settime( 55 : : io_clock_t *clock, const struct timespec *tp); 56 : : 57 : : // clang-format off 58 : : static const struct io_clock_vtbl io_clock_monotonic_vtbl = { 59 : : &io_clock_monotonic_getres, 60 : : &io_clock_monotonic_gettime, 61 : : &io_clock_monotonic_settime 62 : : }; 63 : : // clang-format on 64 : : 65 : : const struct io_clock_monotonic io_clock_monotonic = { 66 : : &io_clock_monotonic_vtbl 67 : : }; 68 : : 69 : : #endif // CLOCK_MONOTONIC 70 : : 71 : : #ifdef CLOCK_REALTIME 72 : : 73 : : static int 74 : 0 : io_clock_realtime_getres(const io_clock_t *clock, struct timespec *res) 75 : : { 76 : : (void)clock; 77 : : 78 : 0 : return clock_getres(CLOCK_REALTIME, res); 79 : : } 80 : : 81 : : static int 82 : 0 : io_clock_realtime_gettime(const io_clock_t *clock, struct timespec *tp) 83 : : { 84 : : (void)clock; 85 : : 86 : 0 : return clock_gettime(CLOCK_REALTIME, tp); 87 : : } 88 : : 89 : : static int 90 : 0 : io_clock_realtime_settime(io_clock_t *clock, const struct timespec *tp) 91 : : { 92 : : (void)clock; 93 : : 94 : 0 : return clock_settime(CLOCK_REALTIME, tp); 95 : : } 96 : : 97 : : #endif // CLOCK_REALTIME 98 : : 99 : : #ifdef CLOCK_MONOTONIC 100 : : 101 : : static int 102 : 0 : io_clock_monotonic_getres(const io_clock_t *clock, struct timespec *res) 103 : : { 104 : : (void)clock; 105 : : 106 : 0 : return clock_getres(CLOCK_MONOTONIC, res); 107 : : } 108 : : 109 : : static int 110 : 3372 : io_clock_monotonic_gettime(const io_clock_t *clock, struct timespec *tp) 111 : : { 112 : : (void)clock; 113 : : 114 : 3372 : return clock_gettime(CLOCK_MONOTONIC, tp); 115 : : } 116 : : 117 : : static int 118 : 0 : io_clock_monotonic_settime(io_clock_t *clock, const struct timespec *tp) 119 : : { 120 : : (void)clock; 121 : : 122 : 0 : return clock_settime(CLOCK_MONOTONIC, tp); 123 : : } 124 : : 125 : : #endif // CLOCK_MONOTONIC